package cn.codingjc.peekaboo.application.config.sql;

import cn.codingjc.peekaboo.application.core.pipeline.BusinessProcess;
import cn.codingjc.peekaboo.application.core.pipeline.ProcessController;
import cn.codingjc.peekaboo.application.core.pipeline.ProcessTemplate;
import cn.codingjc.peekaboo.application.core.sql.process.BuildTableProcess;
import cn.codingjc.peekaboo.application.core.sql.process.ValidSqlSchemaProcess;
import cn.codingjc.peekaboo.domain.common.enums.ProcessContextCodeEnum;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 责任链配置类
 * @date: 2023/5/4
 * @author: Codingjc
 * @className: PipelineConfig
 **/

@Configuration
public class PipelineConfig {

    @Bean
    public ProcessController processController(){
        ProcessController processController = new ProcessController();
        HashMap<String, ProcessTemplate> map = new HashMap<>();
        map.put(ProcessContextCodeEnum.GENERATE_SQL.getCode(), processTemplate());
        processController.setProcessTemplateMap(map);
        return processController;
    }

    @Bean
    public ProcessTemplate processTemplate(){
        ProcessTemplate processTemplate = new ProcessTemplate();
        List<BusinessProcess> businessProcesses = new ArrayList<>();
        businessProcesses.add(new ValidSqlSchemaProcess());
        businessProcesses.add(new BuildTableProcess());
        processTemplate.setBusinessProcesses(businessProcesses);
        return processTemplate;
    }


}
